package com.ruoyi.web.controller.webContent;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.webContent.domain.ZhgsWebContent;
import com.ruoyi.webContent.service.IZhgsWebContentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动态页面数据功能Controller
 * 
 * @author ruoyi
 * @date 2020-05-07
 */
@Controller
@RequestMapping("/webContent/content")
public class ZhgsWebContentController extends BaseController
{
    private String prefix = "webContent/content";

    @Autowired
    private IZhgsWebContentService zhgsWebContentService;

    @RequiresPermissions("webContent:content:view")
    @GetMapping()
    public String content()
    {
        return prefix + "/content";
    }

    /**
     * 查询动态页面数据功能列表
     */
//    @RequiresPermissions("webContent:content:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhgsWebContent zhgsWebContent)
    {
        startPage();
        List<ZhgsWebContent> list = zhgsWebContentService.selectZhgsWebContentList(zhgsWebContent);
        return getDataTable(list);
    }

    /**
     * 导出动态页面数据功能列表
     */
    @RequiresPermissions("webContent:content:export")
    @Log(title = "动态页面数据功能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhgsWebContent zhgsWebContent)
    {
        List<ZhgsWebContent> list = zhgsWebContentService.selectZhgsWebContentList(zhgsWebContent);
        ExcelUtil<ZhgsWebContent> util = new ExcelUtil<ZhgsWebContent>(ZhgsWebContent.class);
        return util.exportExcel(list, "content");
    }

    /**
     * 新增动态页面数据功能
     */
    @GetMapping("/add/{type}")
    public String add(@PathVariable("type") Long type, ModelMap mmap)
    {
        ZhgsWebContent zhgsWebContent = new ZhgsWebContent();
        zhgsWebContent.setType(type);
        mmap.put("zhgsWebContent", zhgsWebContent);
        return prefix + "/add";
//        return prefix + "/completeDemo";

    }

    /**
     * 新增保存动态页面数据功能
     */
    @RequiresPermissions("webContent:content:add")
    @Log(title = "动态页面数据功能", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhgsWebContent zhgsWebContent)
    {
        return toAjax(zhgsWebContentService.insertZhgsWebContent(zhgsWebContent));
    }

    /**
     * 修改动态页面数据功能
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ZhgsWebContent zhgsWebContent = zhgsWebContentService.selectZhgsWebContentById(id);
        mmap.put("zhgsWebContent", zhgsWebContent);
        return prefix + "/edit";
    }

    /**
     * 修改动态页面数据功能
     */
    @GetMapping("/edit_other")
    public String edit_other(ModelMap mmap,ZhgsWebContent zhgsWebContent)
    {
        List<ZhgsWebContent> list = zhgsWebContentService.selectZhgsWebContentList(zhgsWebContent);
//        ZhgsWebContent zhgsWebContent = zhgsWebContentService.selectZhgsWebContentById(id);
        if(list.size()>0){

            mmap.put("zhgsWebContent", list.get(0));
        }
        return prefix + "/xmdt_edit";
    }

    /**
     * 修改保存动态页面数据功能
     */
    @RequiresPermissions("webContent:content:edit")
    @Log(title = "动态页面数据功能", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhgsWebContent zhgsWebContent)
    {
        return toAjax(zhgsWebContentService.updateZhgsWebContent(zhgsWebContent));
    }

    /**
     * 删除动态页面数据功能
     */
    @RequiresPermissions("webContent:content:remove")
    @Log(title = "动态页面数据功能", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhgsWebContentService.deleteZhgsWebContentByIds(ids));
    }
}
